home *** CD-ROM | disk | FTP | other *** search
- #include <iostream.h>
- #include <string.h>
- #include <SIOUX.h>
-
- #include "shell.h"
-
- bool quitting = false;
- bool nocc = true;
- string curd;
-
- int main () {
- init ();
-
- cout << "Welcome to M.A.C.N.A.C.E." << endl;
-
- while (!quitting) {
- if (login ())
- shell ();
- };
-
- cout << "session ended." << endl;
- };
-
- bool login () {
- string id, passwd;
-
- cout << "login: ";
- cin >> id;
- cout << "password: ";
- cin >> passwd;
-
- if (id == "root" && passwd == "2getinit") {
- cout << "Yow!" << endl;
- return true;
- }
- else {
- cout << "login failed." << endl << endl;
- return false;
- };
- };
-
- void shell () {
- char cmds [1000];
- string cmdline;
- long nextpos;
-
- cmds [0] = '\0';
- cout << "# ";
- cout.flush;
- cin.getline (cmds, 1000);
- cin.getline (cmds, 1000);
- cmdline = cmds;
-
- while (!quitting) {
- if (cmdline == "exit") {
- quitting = true;
- continue;
- };
-
- string cmd = parse (cmdline, nextpos);
- cmdline = cmdline.substr (nextpos);
-
- if (cmd == "ps")
- ps (cmdline);
- else if (cmd == "ls")
- ls (cmdline);
- else if (cmd == "kill")
- kill (cmdline);
- else if (cmd == "cat")
- cat (cmdline);
- else if (cmd == "cc")
- cc (cmdline);
- else if (cmd == "cd")
- cd (cmdline);
- else if (cmd == "pwd")
- cout << curd << endl;
- else if (cmd == "a.out" && curd == "/src" && !nocc)
- cout << "hello, world." << endl;
- else
- bad (cmd);
-
- cmdline = "";
- cout << "# ";
- cout.flush;
- cin.getline (cmds, 1000);
- cmdline = cmds;
-
- };
- };
-
- string parse (string line, long& rp) {
- string cmd;
-
- long p;
- p = line.find (" ");
- if (p == string::npos) {
- rp = line.length ();
- return line;
- };
- rp = p + 1;
- cmd = line.substr (0, p);
- return cmd;
- };
-
- void ps (string) {
- string *pname;
- FindRunningTargetApp ();
- cout << "PID UID NAME" << endl;
- for (long i = 0; i < proc; i++) {
- pname = new string (strs [i]);
- cout << setw (3) << i << " root " << *pname << endl;
- delete pname;
- };
- };
-
- void ls (string dir) {
- string wd;
-
- if (dir == "")
- wd = curd;
- else
- wd = dir;
-
- if (wd == "/")
- cout << "bin/ etc/ src/ usr/ " << endl;
- else if (wd == "/src" && nocc)
- cout << "hello.c" << endl;
- else if (wd == "/src" && !nocc)
- cout << "a.out* hello.c" << endl;
- };
-
- void kill (string) {
-
- };
-
- void cat (string file) {
- if (file == "hello.c" && curd == "/src") {
- cout << "#include <stdio.h>" << endl;
- cout << endl;
- cout << "int main () {" << endl;
- cout << " printf (" << '"' << "hello, world." << '\\' << "n" << '"' << ");" << endl;
- cout << "};" << endl;
- };
- };
-
- void cc (string) {
- nocc = false;
- };
-
- void cd (string dir) {
- if (dir == "") {
- curd = "/";
- return;
- };
-
- long p;
- p = dir.find ("/");
- if (p == 0)
- curd = dir;
- else
- curd += dir;
- };
-
- void bad (string cmd) {
- if (cmd != "")
- cout << cmd << " :comand not recognised." << endl;
- };
-
- void init () {
- curd = "/";
- SIOUXSettings.asktosaveonclose = false;
- SIOUXSettings.fontid = kFontIDCourier;
- SIOUXSettings.fontsize = 14;
- SIOUXSettings.toppixel = 20;
- SIOUXSettings.leftpixel = 0;
- SIOUXSettings.columns = 125;
- SIOUXSettings.rows = 51;
- SIOUXSetTitle ((unsigned char *) "\pM.A.C.N.A.C.E.");
- };
-